#! /bin/bash
export LANG=en_US.UTF-8

ip=`ifconfig 2>/dev/null|sed -n 2p|awk  '{ print $2 }'|awk -F : '{ print $2 }'`
pid=$*

if [ $pid ];then
   ports=`netstat -lntp|grep $pid|awk '{print $4}'|awk -F ':' '{print $NF}'`
   http_port=
   for p in $ports
   do
      req_url='http://'$ip':'$p'/'
      response_code=`curl -s  $req_url -w%{http_code} 2>/dev/null -o /dev/null`
      if [[ "$response_code" -gt 199 ]];then
           #http_port=$p
           echo $p
           break
      fi
   done
   #echo $http_port
else
   	echo "miss argument pid!" >2
fi
